#include "os_common.h"

//#ifdef _PE_RX_DUMP_
void DataDmp(UCHAR *pdata, ULONG len, ULONG offset)
{
	UCHAR      dbg_str[140];
	ULONG     i, j, n;
	UCHAR      c;
	UCHAR      *p;

	//WBDEBUG((" addr of pdata = %p\n", pdata));
    for (i = 0; i < len; i += 16)
    {
	    p = dbg_str;

        //--------------------------------------------------------------------
        // Output the offset header
        n = offset + i;

        for (j=0; j<4; j++)
        {
			c = (UCHAR) (n % 16);
            p[3-j] =  (c >= 10) ? 'A'+(c-10) : '0'+c;
			n >>= 4 ;
		}
        p+= 4;

        *p++ = ':';
        *p++ = ' ';

        //--------------------------------------------------------------------
        // Output the hex bytes
        for (j = i; j < (i+16); j++)
        {
            if (j < len)
            {
                c = *(pdata+j) / 16 ;
                *p++ = (c >= 10) ? 'A'+(c-10) : '0'+c;

                c = *(pdata+j) % 16 ;
                *p++ = (c >= 10) ? 'A'+(c-10) : '0'+c;

                *p++ = ' ';
            }
            else
            {
                *p++ = ' ';
                *p++ = ' ';
                *p++ = ' ';
            }
        }

        *p++ = ' ';
        *p++ = ' ';

        //--------------------------------------------------------------------
        // Output the ASCII bytes
        for (j = i; j < (i+16); j++)
        {
            if (j < len)
            {
                c = *(pdata+j);
                *p++ = (! isprint(c)) ? '.' : c;

            }
            else
            {
                *p++ = ' ';
            }
        }

        *p++ = '\n';
        *p++ = '\0';

		//PDEBUG(( "%s", dbg_str));
		WBDEBUG(("%s", dbg_str));

    }
}
//#endif


VOID Mds_MsduProcess( IN PWB32_ADAPTER Adapter, IN PRXLAYER1 pRxLayer1, IN UCHAR SlotIndex)
{
//	phw_data_t	pHwData = &Adapter->sHwData;
	struct MAC_frame_control frame_control;
	struct Data_Frame* pDFrame;
	PUCHAR			SourceAddress;
	PUCHAR			BufAddr;
	USHORT			BufSize;
	USHORT			_8023FrameSize, Temp;
	BOOLEAN			WEPed;
	UCHAR			i;
	UCHAR	mic[8];
	PUCHAR	mic_key = NULL, pframe_mic;
	UCHAR	LastBufIdx;


	// Is management frame??
	if( pRxLayer1->FrameType != MAC_TYPE_DATA )
	{
		// Call MLME function
   		MLMERcvFrame( Adapter, pRxLayer1->BufferQueue, pRxLayer1->BufferNumber, SlotIndex );//The last parameter is needed for SME.
		return;
	}

	// Checking this packet(802.3), if valid for Filter. Just discard the frame if the media is disconnected.
	if ( !CURRENT_LINK_ON )
		return;

	pDFrame = (struct Data_Frame*)pRxLayer1->BufferQueue[0].pBufferAddress;
	//Temp = cpu_to_le16(*(PUSHORT)pRxLayer1->BufferQueue[0].pBufferAddress);
	Temp = (*(PUSHORT)pRxLayer1->BufferQueue[0].pBufferAddress); //anson's endian
	OS_MEMORY_COPY( &frame_control, &Temp, sizeof(USHORT) ); // YY's endian
	WEPed = frame_control.WEP ? TRUE : FALSE;
	if( (!WEPed && !MLMEGetExcludeUnencrypted(Adapter)) ||
		(WEPed && Adapter->sSmePara._dot11PrivacyOptionImplemented != FALSE) )
	{
		//#ifdef _WPA_
		//TODO: check if there is a MIC err
		/**/
		if( WEPed && (pRxLayer1->DecryptionMethod==2) ) //TKIP
		{
			if ((pDFrame->Addr1[0] & 1) == 0)
			{
				if (psSME->pairwise_key_ok)
				{
					mic_key = psSME->rx_mic_key;
				}
			}
			else
			{
				#ifdef _PE_RX_DUMP_
				WBDEBUG(("Receive broadcast/multicast packet.\n"));
				#endif
			}
			if (mic_key == NULL)
			{
				if (psSME->group_key_ok)
				{
					mic_key = psSME->group_rx_mic_key;
				}
				else
				{
					#ifdef _PE_RX_DUMP_
					WBDEBUG(("No key available to decrypt this packet.\n"));
					#endif
					return;
				}
			}

			Mds_MicGet( Adapter, pRxLayer1, mic_key, mic );

			//WBDEBUG(("mic value :\n"));
			//DataDmp(mic, 8, 0);
			//WBDEBUG(("MICKEY = " MICKEYSTR "\n", MICKEY2STR(psSME->rx_mic_key)));
//			#ifdef _PE_RX_DUMP_
//			WBDEBUG(("MICKEY = " MICKEYSTR "\n", MICKEY2STR(mic_key)));
//			WBDEBUG(("MIC    = " MICSTR " (calculate)\n", MIC2STR(mic)));
//			#endif
			//Compare MICs
			// Bug fix for comparing Mic. Due to the mic key maybe devide into 2 parts,
			// driver has to process this situration.
			LastBufIdx = pRxLayer1->BufferNumber - 1;
			pframe_mic = (PUCHAR)pRxLayer1->BufferQueue[ LastBufIdx ].pBufferAddress;
			pframe_mic += pRxLayer1->BufferQueue[LastBufIdx].BufferSize - 8;

			if( memcmp( pframe_mic, mic, 8 ) == 0 )
			{
//				UCHAR *DataPtr = (UCHAR *)pDFrame + 24; // + 24 byte header
//				UCHAR TscValue[6];
//				int j;
/*
				//TKIP Replay protection
				TscValue[0] = DataPtr[2];
				TscValue[1] = DataPtr[0];
				TscValue[2] = DataPtr[4];
				TscValue[3] = DataPtr[5];
				TscValue[4] = DataPtr[6];
				TscValue[5] = DataPtr[7];
				j = 5;
				if ((pDFrame->Addr1[0] & 1) == 0)
				{
					while (TscValue[i] <= psBSS(SlotIndex)->PairwiseTSC[j])
					{
						j--;
						if (i<0)
							break;
					}
					if (i>=0)
						memcpy(psBSS(SlotIndex)->PairwiseTSC, TscValue, 6);
					else
					{
						WBDEBUG(("pairwise replay\n"));
						return;//replay
					}
				}
				else//group
				{
					while (TscValue[j] <= psBSS(SlotIndex)->GroupTSC[j])
					{
						j--;
						if (j<0)
							break;
					}
					if (j>=0)
						memcpy(psBSS(SlotIndex)->GroupTSC, TscValue, 6);
					else
					{
						WBDEBUG(("group replay\n"));
						return;//replay
					}
				}
*/
				//exclude the MIC
				pRxLayer1->BufferQueue[ LastBufIdx ].BufferSize -= 8;
			}
			else
			{

			//	#ifdef _PE_RX_DUMP_
				WBDEBUG(("!!!!!! MIC error !!!!!!\n"));
			//	#endif

//				MDS_EVENT_AUTH_REQUEST_PAIRWISE_ERROR( Adapter );

				#ifdef NDIS51_MINIPORT
				if (mic_key == psSME->rx_mic_key)
					{ MDS_EVENT_INDICATE( Adapter,
										  psBSS(Adapter->sLocalPara.wConnectedSTAindex)->abBssID,
										  AUTH_REQUEST_PAIRWISE_ERROR ); }
				else
					{ MDS_EVENT_INDICATE( Adapter,
										  psBSS(Adapter->sLocalPara.wConnectedSTAindex)->abBssID,
										  AUTH_REQUEST_GROUP_ERROR ); }

				Adapter->Mds.bMICfailCount++;

				if (Adapter->Mds.bMICfailCount == 1)
				{
					vRxTimerStart(Adapter, 60000);//60s
				}
				if (Adapter->Mds.bMICfailCount == 2)
				{
					//Adapter->Mds.bMICfailCount = 0;
					Adapter->Mds.boCounterMeasureBlock = 1;
					#ifdef _PE_RX_DUMP_
					WBDEBUG(("!!!!!! Countermeasure Block  !!!!!!\n"));
					#endif
					vRxTimerStop(Adapter);
					//Start Countermeasure block timer
					vRxTimerStart(Adapter, 60000);//60s
				}
				#endif

				return;
			}
		}
		//#endif // End of _WPA_

		//--------------------------------------------
		//    Convert 802.11 frame to 802.3 frame
		//--------------------------------------------

		// Updating the MSDU counter 'GS_RCV_OK'
		MIB_GS_RCV_OK_INC;

		//Get the Source address
		SourceAddress = pDFrame->Addr3;
		if( !frame_control.from_ds )
			SourceAddress = pDFrame->Addr2;

		BufSize = pRxLayer1->BufferQueue[0].BufferSize;
		BufAddr = pRxLayer1->BufferQueue[0].pBufferAddress;

		//Point to the frame body
		BufAddr += (DOT_11_TYPE_OFFSET - ETH_LENGTH_OF_ADDRESS); // offset 24 is 4n alignment @@

		// PD43 20021220 Added for Type/Length encapsulation adjust
//		if( *(PULONG)BufAddr==0x0003aaaa      && // little endian
//			*(PULONG)(BufAddr+4)!=0x37810000  && //PD43 20030418 Modified for HCT 11
//			(*(PUSHORT)(BufAddr+4)==0 || *(PUSHORT)(BufAddr+4)==0xf800) )
		// YY's endian
		if( *(PULONG)BufAddr==cpu_to_le32(0x0003aaaa)      && // little endian // @@ 4n alignment here
			*(PULONG)(BufAddr+4)!=cpu_to_le32(0x37810000)  && //PD43 20030418 Modified for HCT 11 // @@ 4n alignment here
			(*(PUSHORT)(BufAddr+4)==0 || *(PUSHORT)(BufAddr+4)==cpu_to_le16(0xf800)) ) // @@ 4n alignment here
		{
			// Converted to Type-encapsulated 802.3 frame.
			// Do nothing here
			pRxLayer1->TypeEncapsulated = TRUE;
			pRxLayer1->BufferQueue[0].BufferSize -= 18;
		}
		else
		{
			// Converted to Length-encapsulated 802.3 frame.
			// Reserved 2 bytes for length field.
			BufAddr -= (2 + ETH_LENGTH_OF_ADDRESS);
			pRxLayer1->TypeEncapsulated = FALSE;
			pRxLayer1->BufferQueue[0].BufferSize -= 10;
		}

		OS_MEMORY_COPY( BufAddr, SourceAddress, MAC_ADDR_LENGTH );

		// Copy DA
		BufAddr -= ETH_LENGTH_OF_ADDRESS;
		SourceAddress = pRxLayer1->BufferQueue[0].pBufferAddress + DOT_11_DA_OFFSET;
		OS_MEMORY_COPY( BufAddr, SourceAddress, MAC_ADDR_LENGTH );
		pRxLayer1->BufferQueue[0].pBufferAddress = BufAddr;

		// Is 802.3 frame format?
		if( !pRxLayer1->TypeEncapsulated )
		{
			_8023FrameSize = 0; // PD43 20021220 Added
			for( i=0; i<pRxLayer1->BufferNumber; i++ )
			{
				BufSize = pRxLayer1->BufferQueue[i].BufferSize;
				_8023FrameSize += BufSize;
			}

			//modify the length field
			_8023FrameSize -= (6 + 6 + 2);  // DA + SA + Type/Len
			Temp            = (_8023FrameSize & 0xff00) >> 8;
			_8023FrameSize  = (_8023FrameSize << 8) | Temp;
			*((PUSHORT)&pRxLayer1->BufferQueue[0].pBufferAddress[12]) = cpu_to_le16(_8023FrameSize); // YY's endian
		}

		// Indicate to Upper Module
		MDS_EthernetPacketReceive( Adapter, pRxLayer1 );
		Adapter->sLocalPara._NumRxMSDU ++;// A packet be indicated
	}
	else
	{
		if( !WEPed )
			Adapter->sLocalPara._dot11WEPExcludedCount ++;
		else
			Adapter->sLocalPara._dot11WEPUndecryptableCount ++;
	}// End of if( (!WEPed && !MLMEGetExcl...
}

void vRxTimerInit(PWB32_ADAPTER Adapter)
{
	OS_TIMER_INITIAL( &(Adapter->Mds.nTimer),
                          (PVOID) RxTimerHandler,
                          (PVOID) Adapter);
}

void vRxTimerStart(PWB32_ADAPTER Adapter, int timeout_value)
{
    if (timeout_value<MIN_TIMEOUT_VAL)
		timeout_value=MIN_TIMEOUT_VAL;
	
	OS_TIMER_SET( &(Adapter->Mds.nTimer), timeout_value );
}

void vRxTimerStop(PWB32_ADAPTER Adapter)
{
//   BOOLEAN boValue=TRUE;

//For clean compile
//	OS_TIMER_CANCEL( &(Adapter->Mds.nTimer), &boValue );
	OS_TIMER_CANCEL( &(Adapter->Mds.nTimer), 0 );
}

void RxTimerHandler_1a(IN PADAPTER Adapter)
{
	RxTimerHandler(NULL, Adapter, NULL, NULL);
}
void RxTimerHandler(IN PVOID			SystemSpecific1,
					  IN PWB32_ADAPTER 	Adapter,
					  IN PVOID			SystemSpecific2,
					  IN PVOID			SystemSpecific3)
{
	K_MSG sMsg;
	USHORT		wReasonCode;

	if (Adapter->Mds.bMICfailCount == 1)
	{
		sMsg.wMsgType = SMEMSG_COUNTERMEASURE_MICFAIL_TIMEOUT;
	}
	if (Adapter->Mds.boCounterMeasureBlock == 1)
	{
		if (psLOCAL->wConnectedSTAindex != 0)
		{
			//Wait for NDIS to send MIC error EAPOL packet, and then disassoc.
			//But it doesn't appear.
			#ifdef _PE_STATE_DUMP_
			WBDEBUG(("!!Countermeasure, block timeout, disassoc !!\n"));
			#endif

			FillEventLog(Adapter, EVENT_COUNTERMEASURE);

			wReasonCode = REASON_MIC_ERROR;
			sMsg.wMsgType = SMEMSG_DISASSOC_REQ;
			sMsg.pMsgPtr = &wReasonCode;
			SME_Entry(Adapter, &sMsg);
		}
	    sMsg.wMsgType = SMEMSG_COUNTERMEASURE_BLOCK_TIMEOUT;
	}
	sMsg.pMsgPtr = NULL;
	SME_Entry(Adapter, &sMsg);
}

// For efficiency, the routine supports packet indicating asynchronous.
// If the Descriptor status macro DESCRIPTOR_STATUS_RESOURCES is true.
// the asynchronous indicating can be achieved.
VOID Mds_MpduProcess( IN PWB32_ADAPTER Adapter, IN PDESCRIPTOR pRxDes )
{
	struct Data_Frame* pDataFrame;
	phw_data_t	pHwData = &Adapter->sHwData;
	PUCHAR		pBufferAddress;
	PUCHAR		pMyMACAddr;
	PRXLAYER1	pRxLayer1;
	USHORT		BufferSize;
	USHORT		FrameArrivedTime;
	USHORT		SequenceNumber;
	UCHAR		FragmentNumber;
	UCHAR		ReturnSlotIndex;
	UCHAR		i;

	#ifdef _PE_RX_DUMP_
	//[WK DUMP]
	//if ((*((PUCHAR)pRxDes->buffer_address[0]) != 0x80) &&
	//	(*((PUCHAR)pRxDes->buffer_address[0]) != 0x40))
	if ( *((PUCHAR)pRxDes->buffer_address[0]) == 0x08)
	{
		ChanInfo ChanTmp;

		WBDEBUG(("$$$$$ DUMP RX MPDU $$$$$\n"));
		hal_get_current_channel(&Adapter->sHwData, &ChanTmp);
		WBDEBUG(("ChanNo = %d, ChanBand =%d \n", ChanTmp.ChanNo, ChanTmp.band));
		for (i=0; i<pRxDes->buffer_number; i++)
		{
			DataDmp(pRxDes->buffer_address[i], pRxDes->buffer_size[i], 0);
		}
	}
	#endif

	FrameArrivedTime = DESCRIPTOR_RX_RECEIVE_TIME( pRxDes );
	pBufferAddress = pRxDes->buffer_address[0];// Get the first buffer for processing
	pDataFrame = pRxDes->buffer_address[0];// Get the first buffer for processing
	BufferSize = pRxDes->buffer_size[0];

	do
	{
		// 911014.1 Checking for frame if receive fail
		if( DESCRIPTOR_RX_STATUS_ERROR( pRxDes ) )
		{
			USHORT seq;
			seq = cpu_to_le16(*(PUSHORT)(pBufferAddress+22));  //20060926 anson's endian
			seq >>= 4;
			#ifdef _PE_RX_DUMP_
			WBDEBUG(("Rx[%d] flag err = %x\n", seq, pRxDes->R01.value));
			#endif
			Adapter->sLocalPara.GS_RCV_ERROR++;
			//TODO:
			pHwData->rx_err_count[0]++;
			break;
		}
		else
		{
			pHwData->rx_ok_count[0]++;
		}

		// Not a Management or Data frame
		i = pDataFrame->frame_control.mac_frame_info;
		if( ((i&0x0f)!=MAC_TYPE_MANAGEMENT) && (i!=MAC_TYPE_DATA) )
		{
			#ifdef _PE_RX_DUMP_
			WBDEBUG(("Rx Not a Management and Data(Null) frame. Type=%x\n", i));
			#endif
			break;
		}

		// Is a station role
		if( pDataFrame->frame_control.to_ds )
		{
			#ifdef _PE_STATE_DUMP_
			WBDEBUG(("Rx not a station role\n"));
			#endif
			#ifdef _PE_RX_DUMP_
			//[WK DUMP]
			WBDEBUG(("$$$$$ DUMP ERR RX MPDU $$$$$\n"));
			for (i=0; i<pRxDes->buffer_number; i++)
			{
				DataDmp(pRxDes->buffer_address[i], pRxDes->buffer_size[i], 0);
			}
			#endif
			break;
		}

		// Get the SA from incoming frame
		pMyMACAddr = pDataFrame->Addr2;

		// Searching the SA in the Descriptor database
		if ((ReturnSlotIndex=(UCHAR)wBSSsearchMACaddr(Adapter, pMyMACAddr, psLOCAL->CurrentChan.band)) == 0)
		{
			#ifdef _PE_STATE_DUMP_
			WBDEBUG(("$$$ New Idx, band =%d\n", psLOCAL->CurrentChan.band));
			DataDmp( pMyMACAddr, 6, 0);
			#endif

			if ((ReturnSlotIndex=(UCHAR)wBSSGetEntry(Adapter)) == 0)
				break;	// Dropt
			else
			{
				OS_MEMORY_COPY( psBSS(ReturnSlotIndex)->abPeerAddress, pMyMACAddr, MAC_ADDR_LENGTH );

				//if( HAL_HW_VERSION( pHwData ) < 0x200 ) // For FA
					psBSS(ReturnSlotIndex)->band = psLOCAL->CurrentChan.band;
				//else
				//{
				//	if (DESCRIPTOR_RX_STATUS_BAND(pRxDes))
				//		psBSS(ReturnSlotIndex)->band = BAND_TYPE_OFDM_5;
				//	else
				//		psBSS(ReturnSlotIndex)->band = BAND_TYPE_OFDM_24;
				//}
			}
		}
		pRxLayer1 = &psBSS(ReturnSlotIndex)->RxLayer1;



		// Get the frame information
		FragmentNumber = cpu_to_le16( pDataFrame->Sequence_Control ) & MASK_FRAGMENT_NUMBER ;//20060926 anson's endian
		SequenceNumber = cpu_to_le16( pDataFrame->Sequence_Control ) >> SEQUENCE_NUMBER_SHIFT; //20060926 anson's endian

		// Is Sequence Number match?
		if( SequenceNumber == pRxLayer1->SequenceNumber )
		{
			if( pRxLayer1->DeFragmentNumber > FragmentNumber )
				Adapter->sLocalPara._dot11FrameDuplicateCount ++;

			// Is Fragment Number match
			if( pRxLayer1->InUsed ) //910829.2 If waiting for another Fragment
			{
				if( pRxLayer1->DeFragmentNumber != FragmentNumber )
					break;
			}
			else
			{
				// 20061004 For fix intel 3945 ABG 's bug
				i = pBufferAddress[0] & 0xfc;
				if( ( i != 0x80 ) && // Not a beacon
					( i != 0x50 ) && // Not a probe response
					//[20041005 wkchen]
					//89c35 H/W will lanuch probe responses with zero sequence number.
					//So if the peer BSS is 89c35 device, we may mis-judge and drop probe responses
					//when the BSS descriptor entry is newly allocated.
					( (pRxLayer1->LastFrameType&0xfc) != 0x80 ) ) // Last time received does not a beacon
					break;
			}
		}
		else
		{
			if( FragmentNumber )
				break; //910923.8 Add this condition checking

			if( pRxLayer1->InUsed )// Return resource
			{
//				pRxLayer1->BufferQueue[0].BufferSize = 0;
			}

			// Updating RxLayer1
			pRxLayer1->SequenceNumber = SequenceNumber;
		}

		pRxLayer1->LastFrameType = pBufferAddress[0]; // 20061004 For fix intel 3945's bug

		// 910918.5 Store the fragment flag
		pRxLayer1->InUsed = pDataFrame->frame_control.more_frag;
		pRxLayer1->FrameType = pDataFrame->frame_control.mac_frame_info & MASK_PROTOCOL_VERSION_TYPE;

		//-------------------------------------------------------------------
		// Frame has passed the entire check. Fill information into RxLayer1
		//-------------------------------------------------------------------
		//psBSS(ReturnSlotIndex)->HalRssi = pRxDes->R01.value;// Update RSSI
		//ws added for wep error detection in 02/02/05
		
        if( boCmpMacAddr( pDataFrame->Addr3, Adapter->sLocalPara.ThisMacAddress ) )
                Adapter->sLocalPara.bToSelfPacketReceived = TRUE;

		psBSS(ReturnSlotIndex)->HalRssi[psBSS(ReturnSlotIndex)->HalRssiIndex++] = pRxDes->R01.value;// Update RSSI
		psBSS(ReturnSlotIndex)->HalRssiIndex %= MAX_ACC_RSSI_COUNT;

		if( FragmentNumber ) // Cut the 802.11 header
		{
			pBufferAddress += DOT_11_DATA_OFFSET;
			BufferSize -=  DOT_11_DATA_OFFSET;
			pRxLayer1->BufferTotalSize += BufferSize;
		}
		else
		{
			pRxLayer1->DecryptionMethod = DESCRIPTOR_RX_DECRYPTION_METHOD( pRxDes );
			pRxLayer1->FirstFrameArrivedTime = FrameArrivedTime;// Update the First frame arrived time
			pRxLayer1->DeFragmentNumber = 0;
			pRxLayer1->BufferNumber = 0;
			pRxLayer1->BufferTotalSize = BufferSize;
		}

		//Update total number of buffer
		pRxLayer1->DeFragmentNumber++;

		// Copy data into buffer, if fragmental frame
		if( pDataFrame->frame_control.more_frag )
		{
			if( !FragmentNumber )
			{
				pRxLayer1->ReservedBufferPoint = pRxLayer1->ReservedBuffer;//Initial the point for reserved zone
				pRxLayer1->BufferQueue[0].pBufferAddress = pRxLayer1->ReservedBuffer;
				pRxLayer1->BufferQueue[0].BufferSize = 0;
				pRxLayer1->BufferNumber = 1;
			}

			pRxLayer1->BufferQueue[0].BufferSize += BufferSize;
			OS_MEMORY_COPY( pRxLayer1->ReservedBufferPoint, pBufferAddress, BufferSize );
			pRxLayer1->ReservedBufferPoint += BufferSize; //Move to the next available start address
		}
		else
		{
			// 802.11 MSDU Complete
			if( FragmentNumber )
			{
				// To ensure that all the fragment are in one buffer.
				OS_MEMORY_COPY( pRxLayer1->ReservedBufferPoint, pBufferAddress, BufferSize );
				pRxLayer1->BufferQueue[0].BufferSize += BufferSize;
			}
			else
			{
				pRxLayer1->BufferQueue[0].pBufferAddress = pBufferAddress;
				pRxLayer1->BufferQueue[0].BufferSize = BufferSize;
				pRxLayer1->BufferNumber = 1;
			}

			// PD43 20030117 Added for evaluating whether the remote STA has entered the PS mode.
			psBSS(ReturnSlotIndex)->PowerSaveMode = FALSE;
			if( pDataFrame->frame_control.pwr_mgt )
				psBSS(ReturnSlotIndex)->PowerSaveMode = TRUE;


			if( (FrameArrivedTime - pRxLayer1->FirstFrameArrivedTime) < 1000 )//For IS89C35 = 1sec
			{
				// Packet processing
				Mds_MsduProcess( Adapter, pRxLayer1, ReturnSlotIndex);
			}
			else
			{
				#ifdef _PE_STATE_DUMP_
				WBDEBUG(("!!RX Error!!: excess the max receive life time\n"));
				#endif
			}
		}

		return;
	}while(FALSE);
}


